package com.ruoyi.web.controller.sz;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.entity.SisSysOrgan;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.system.service.sz.ISisSysOrganService;
import com.ruoyi.system.service.sz.ISisSysUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 统一组织机构Controller
 * 
 * @author ruoyi
 * @date 2024-03-22
 */
@Anonymous
@RestController
@RequestMapping("/sz/organ")
public class SisSysOrganController extends BaseController
{
    @Autowired
    private ISisSysOrganService sisSysOrganService;

    @Autowired
    private ISisSysUserService sisSysUserService;

    /**
     * 查询统一组织机构列表
     */
//    @PreAuthorize("@ss.hasPermi('sz:organ:list')")
    @GetMapping("/list")
    public TableDataInfo list(SisSysOrgan sisSysOrgan)
    {
        startPage();
        List<SisSysOrgan> list = sisSysOrganService.selectSisSysOrganList(sisSysOrgan);
        return getDataTable(list);
    }

    /**
     * 导出统一组织机构列表
     */
//    @PreAuthorize("@ss.hasPermi('sz:organ:export')")
//    @Log(title = "统一组织机构", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SisSysOrgan sisSysOrgan)
    {
        List<SisSysOrgan> list = sisSysOrganService.selectSisSysOrganList(sisSysOrgan);
        ExcelUtil<SisSysOrgan> util = new ExcelUtil<SisSysOrgan>(SisSysOrgan.class);
        util.exportExcel(response, list, "统一组织机构数据");
    }

    /**
     * 获取统一组织机构详细信息
     */
//    @PreAuthorize("@ss.hasPermi('sz:organ:query')")
    @GetMapping(value = "/{objuid}")
    public AjaxResult getInfo(@PathVariable("objuid") String objuid)
    {
        return success(sisSysOrganService.selectSisSysOrganByObjuid(objuid));
    }

    /**
     * 新增统一组织机构
     */
//    @PreAuthorize("@ss.hasPermi('sz:organ:add')")
//    @Log(title = "统一组织机构", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SisSysOrgan sisSysOrgan)
    {
        return toAjax(sisSysOrganService.insertSisSysOrgan(sisSysOrgan));
    }

    /**
     * 修改统一组织机构
     */
//    @PreAuthorize("@ss.hasPermi('sz:organ:edit')")
//    @Log(title = "统一组织机构", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SisSysOrgan sisSysOrgan)
    {
        return toAjax(sisSysOrganService.updateSisSysOrgan(sisSysOrgan));
    }

    /**
     * 删除统一组织机构
     */
//    @PreAuthorize("@ss.hasPermi('sz:organ:remove')")
//    @Log(title = "统一组织机构", businessType = BusinessType.DELETE)
	@DeleteMapping("/{objuids}")
    public AjaxResult remove(@PathVariable String[] objuids)
    {
        return toAjax(sisSysOrganService.deleteSisSysOrganByObjuids(objuids));
    }

    @GetMapping("/deptTree")
    public AjaxResult deptTree(SisSysOrgan sisSysOrgan)
    {
        return success(sisSysOrganService.selectSisSysOrganTreeList(sisSysOrgan));
    }

    @GetMapping("/getUser")
    public AjaxResult getUserByOrg(String orgId)
    {
        return success(sisSysUserService.selectSisSysUserByOrgId(orgId));
    }
}
